package data

import (
	"database/sql"
	"log"
)

type UserRepo struct {
	db *sql.DB
}

func NewUserRepo(db *sql.DB) *UserRepo {
	return &UserRepo{
		db: db,
	}
}

func (u *UserRepo) GetUser(id int) (*UserPO, error) {
	sqlStr := "select id, username, age from user where id=?"
	user := &UserPO{}
	err := u.db.QueryRow(sqlStr, id).Scan(&user.UserId, &user.UserName, &user.Age)
	log.Println("GetUser From db  err:", err)
	if err != nil {
		return user, err
	}
	return user, nil
}

type UserPO struct {
	UserId     int
	UserName   string
	Password   string
	Age        int
	LoginTime  int
	CreateTime int
}
